﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ControlModule.Daos;
using ControlModule.Models;

namespace ControlModule.QuizModule
{
    public class ControlQuestionManager
    {
        private static ControlQuestionManager _instance;
        private ControlQuestionManager() { }
        public static ControlQuestionManager Get()
        {
            return _instance ?? (_instance = new ControlQuestionManager());
        }

        private List<FullControlQuestion> _fullControlQuestions = null;
        private List<FullControlQuestion>.Enumerator _enumerator;

        public bool IsControlQuestionLoaded()
        {
            return _fullControlQuestions != null;
        }

        public void LoadFullControlQuestionsForLabwork(int labworkId)
        {
            _fullControlQuestions = new List<FullControlQuestion>();
            foreach (RelLabworkControlQuestion rlcq in ControlQuestionDao.LoadRelationsLabworkControlQuestion(labworkId))
            {
                FullControlQuestion question = new FullControlQuestion();
                question.QuestionId = rlcq.ControlQuestionId;
                question.QuestionText = ControlQuestionDao.GetTextQuestionByQuestionId(rlcq.ControlQuestionId);
                question.AnswerText = "";
                _fullControlQuestions.Add(question);
            }
            _enumerator = _fullControlQuestions.GetEnumerator();
        }

        public FullControlQuestion ReadNext()
        {
            if (_enumerator.MoveNext())
                return _enumerator.Current;
            return null;
        }
    }
}